/**
 * 
 */
package net.toocruel.iqismart.dao.spec;

import net.toocruel.iqismart.dao.condition.QuestionsCondition;
import net.toocruel.iqismart.dao.support.BaseSpecification;
import net.toocruel.iqismart.dao.support.QueryWraper;
import net.toocruel.iqismart.entity.core.Question;
import org.apache.commons.lang.StringUtils;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Root;

/**
 * @author toocruel
 *
 */
public class QuestionsSpec extends BaseSpecification<Question, QuestionsCondition> {

	public QuestionsSpec(QuestionsCondition condition) {
		super(condition);
	}

	@Override
	protected void addCondition(QueryWraper<Question> queryWraper) {
		CriteriaBuilder cb = queryWraper.getCb();
		Root<Question> root = queryWraper.getRoot();


		Long categoryId = getCondition().getCategoryId();
		String filter = getCondition().getFilter();
		if(categoryId !=null && categoryId >0){
			cb.and(cb.equal(root.get("category"), categoryId));
		}

		if(StringUtils.isNotBlank(filter)){
			//newest hottest reward unAnswered
			if("newest".equals(filter)){

			}
		}



	}

	@Override
	protected void addFetch(Root<Question> root) {

	}
}
